package com.huabo.system.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hbfk.util.JsonBean;
import com.huabo.system.oracle.entity.TblSystemSheetTable;
import com.huabo.system.service.YinMaiBusinessService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
@Api(value = "引迈工作流Controller", tags = {"引迈的工作流Controoler"})
@RequestMapping("/ymWrok")
public class YinMaiWorkFlowController {

	
	@Resource
	public YinMaiBusinessService yinMaiBusinessService;
	
	@RequestMapping(value = "/saveWorkFlowFormInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiParam("工作流设计-新建工作流，保存信息")
    public JsonBean saveWorkFlowFormInfo(HttpServletRequest reques,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="workName",value="工作流名称",required=true) @RequestParam(value = "workName", required = true) String workName,
    		@ApiParam(name="ymWorkId",value="工作流主键",required=false) @RequestParam(value = "ymWorkId", required = false) String ymWorkId,
    		@ApiParam(name="tablId",value="表单ID",required=true) @RequestParam(value = "tablId", required = true) Integer tablId) throws Exception {
        return this.yinMaiBusinessService.saveWorkFlowFormInfo(token,workName,tablId,ymWorkId);
    }
	
	@RequestMapping(value = "/getSystemFlowList", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
    @ApiParam("工作流设计-获取系统表单信息")
    public JsonBean getSystemFlowList(HttpServletRequest reques,TblSystemSheetTable sheet,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token) throws Exception {
        return this.yinMaiBusinessService.getSystemFlowList(token,sheet);
    }
	
	
	
	@RequestMapping(value = "/getWorFlowList", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
    @ApiParam("工作流设计、审批列表-获取所有工作流信息")
    public JsonBean getWorFlowList(HttpServletRequest reques,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="workName",value="工作流名称",required=false) @RequestParam(value = "workName", required = false) String workName,
    		@ApiParam(name="tablId",value="表单ID",required=true) @RequestParam(value = "tablId", required = true) Integer tablId) throws Exception {
        return this.yinMaiBusinessService.getWorkFlowList(token,workName,tablId);
    }
	
	@RequestMapping(value = "/submit", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
    @ApiParam("审批列表-提交审批")
    public JsonBean submit(HttpServletRequest reques,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="fromId",value="表单主键",required=true) @RequestParam(value = "fromId", required = true) Integer fromId,
    		@ApiParam(name="flowId",value="工作流主键",required=true) @RequestParam(value = "flowId", required = true) String flowId) throws Exception {
        return this.yinMaiBusinessService.submit(token,fromId,flowId);
    }
	
}
